/**
 * 添加或者修改页面
 */
var ArchiveInfoInfoDlg = {
    data: {
        wjid: "",
        mc: "",
        dalx: "",
        ssbmid: "",
        ssrrmc: "",
        mj: "",
        glnx: "",
        nd: "",
        qsnd: "",
        jsnd: "",
        dahid: "",
        ly: "",
        bz: "",
        sfyx: ""
    }
};

layui.use(['form', 'admin', 'ax', 'table', 'func', 'element', 'formSelects','util'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var el = layui.element;
    var fs = layui.formSelects;


    var infoTable = new Info(layui);

    var fileTable = new Files(layui);

    var archive = new Archive(layui);

    infoTable.setItemSelect(function (index, data) {
        fileTable.setParentId(data.id);
    })

    archive.setItemSelect(function (index, data) {
        infoTable.setParentId(data.id);
    })


    //让当前iframe弹层高度适应
    admin.iframeAuto();

    fs.on('dag', function (id, vals, val, isAdd, isDisabled) {
        var values = val.value.split("/");
        if (values.length == 4) {
            $("#dahid").val(values[3]);
            return true;
        }
        Feng.error("数据不全，无法选取");
        //如果return false, 那么将取消本次操作
        return false;
    });


    function disableForm() {
        //添加成功之后，禁用掉自己
        $("#btnSubmit").attr("disabled", "");
        $("#archiveInfoForm [name]").addClass("layui-disabled").attr("disabled", "");
        fs.disabled();
        //显示下面的表单
        $("#twoTable").removeClass("layui-hide");
    }

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/archiveInfo/addItem", function (data) {
            Feng.success("添加成功！");
            disableForm();
            infoTable.setParentId(data.data.id);
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/archiveInfo'
    });


});